﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace FlyingEye.Migrations
{
    /// <inheritdoc />
    public partial class FirstMigrations : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AppDeviceClients",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    Site = table.Column<int>(type: "int", nullable: false),
                    ProcessName = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ResourceId = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppDeviceClients", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AppReadNumericValueTasks",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    DeviceClientId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    TaskName = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DeviceName = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Address = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DataType = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Interval = table.Column<int>(type: "int", nullable: false),
                    Enable = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    UniqueHashKey = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppReadNumericValueTasks", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppReadNumericValueTasks_AppDeviceClients_DeviceClientId",
                        column: x => x.DeviceClientId,
                        principalTable: "AppDeviceClients",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AppReadStringValueTasks",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    DeviceClientId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    TaskName = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DeviceName = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Address = table.Column<string>(type: "longtext", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Length = table.Column<int>(type: "int", nullable: false),
                    Interval = table.Column<int>(type: "int", nullable: false),
                    Enable = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    UniqueHashKey = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppReadStringValueTasks", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppReadStringValueTasks_AppDeviceClients_DeviceClientId",
                        column: x => x.DeviceClientId,
                        principalTable: "AppDeviceClients",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AppNumericValueMonitorClients",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ReadNumericValueTaskId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ClientName = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppNumericValueMonitorClients", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppNumericValueMonitorClients_AppReadNumericValueTasks_ReadN~",
                        column: x => x.ReadNumericValueTaskId,
                        principalTable: "AppReadNumericValueTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AppNumericValueMonitorGroups",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ReadNumericValueTaskId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    GroupName = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppNumericValueMonitorGroups", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppNumericValueMonitorGroups_AppReadNumericValueTasks_ReadNu~",
                        column: x => x.ReadNumericValueTaskId,
                        principalTable: "AppReadNumericValueTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AppStringValueMonitorClients",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ReadStringValueTaskId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ClientName = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppStringValueMonitorClients", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppStringValueMonitorClients_AppReadStringValueTasks_ReadStr~",
                        column: x => x.ReadStringValueTaskId,
                        principalTable: "AppReadStringValueTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "AppStringValueMonitorGroups",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ReadStringValueTaskId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    GroupName = table.Column<string>(type: "varchar(255)", nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreatorId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    LastModificationTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppStringValueMonitorGroups", x => x.Id);
                    table.ForeignKey(
                        name: "FK_AppStringValueMonitorGroups_AppReadStringValueTasks_ReadStri~",
                        column: x => x.ReadStringValueTaskId,
                        principalTable: "AppReadStringValueTasks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_AppDeviceClients_ResourceId",
                table: "AppDeviceClients",
                column: "ResourceId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppDeviceClients_Site_ProcessName",
                table: "AppDeviceClients",
                columns: new[] { "Site", "ProcessName" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppNumericValueMonitorClients_ReadNumericValueTaskId_ClientN~",
                table: "AppNumericValueMonitorClients",
                columns: new[] { "ReadNumericValueTaskId", "ClientName" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppNumericValueMonitorGroups_ReadNumericValueTaskId_GroupName",
                table: "AppNumericValueMonitorGroups",
                columns: new[] { "ReadNumericValueTaskId", "GroupName" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppReadNumericValueTasks_DeviceClientId",
                table: "AppReadNumericValueTasks",
                column: "DeviceClientId");

            migrationBuilder.CreateIndex(
                name: "IX_AppReadNumericValueTasks_TaskName",
                table: "AppReadNumericValueTasks",
                column: "TaskName",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppReadNumericValueTasks_UniqueHashKey",
                table: "AppReadNumericValueTasks",
                column: "UniqueHashKey",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppReadStringValueTasks_DeviceClientId",
                table: "AppReadStringValueTasks",
                column: "DeviceClientId");

            migrationBuilder.CreateIndex(
                name: "IX_AppReadStringValueTasks_TaskName",
                table: "AppReadStringValueTasks",
                column: "TaskName",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppReadStringValueTasks_UniqueHashKey",
                table: "AppReadStringValueTasks",
                column: "UniqueHashKey",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppStringValueMonitorClients_ReadStringValueTaskId_ClientName",
                table: "AppStringValueMonitorClients",
                columns: new[] { "ReadStringValueTaskId", "ClientName" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppStringValueMonitorGroups_ReadStringValueTaskId_GroupName",
                table: "AppStringValueMonitorGroups",
                columns: new[] { "ReadStringValueTaskId", "GroupName" },
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AppNumericValueMonitorClients");

            migrationBuilder.DropTable(
                name: "AppNumericValueMonitorGroups");

            migrationBuilder.DropTable(
                name: "AppStringValueMonitorClients");

            migrationBuilder.DropTable(
                name: "AppStringValueMonitorGroups");

            migrationBuilder.DropTable(
                name: "AppReadNumericValueTasks");

            migrationBuilder.DropTable(
                name: "AppReadStringValueTasks");

            migrationBuilder.DropTable(
                name: "AppDeviceClients");
        }
    }
}
